﻿using System;
using System.Collections;
using System.Linq;

namespace eCommerce.DataAccess
{
    public class SearchDA
    {
        public static ArrayList SearchProducts(String query)
        {
            SiteProductsDataContext siteProductsDataContext = new SiteProductsDataContext();
            ArrayList list = new ArrayList();

            var str = query;
            var newStr = str.Split(' ');
            foreach (var arrStr in newStr)
            {
                if (arrStr == null) continue;
                var posts =
                    siteProductsDataContext.Products.OrderByDescending(sq => sq.ProductName).Where(
                        sq => sq.ProductName.Contains(arrStr) || sq.ProductDesc.Contains(arrStr));
                list.Add(posts);
                //i++;
                //result.AsEnumerable();
            }

            return list;
        }
    }
}
